package nl.hu.verbrandendephoenix.view;

import nl.hu.verbrandendephoenix.shared.Conversation;

import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.VerticalPanel;

public class Inbox {
	private VerticalPanel vp = new VerticalPanel();
	private FlexTable t = new FlexTable();
	
	public Inbox() {}
	
	public VerticalPanel get() {
		t.setText(0, 0, "Conversation partner");
		t.setStyleName("inboxtable");
		vp.add(t);
		return vp;
	}
	
	public void addConv(int i, Conversation c) {
		//Make sure no more than 20 characters of the message are viewed in the table
		String entry = c.getLast();
		if(entry.length() > 20) {
			entry = entry.substring(0, 17) + "...";
		}
		i++;
		t.setText(i, 0, c.getContact().getUserName()); //new anchor met c.getCID();
		t.setText(i, 1, entry);
		t.setWidget(i, 2, new Anchor("Bekijk", "#conversation_" + c.getCID()));
		
	}
	
	public void removeConv(int i) {
		t.removeRow(i);
	}
	
}
